<?
function getlistMenuAd($name,$selected="")
{
	$q = query("select * from admin_menu order by sort asc");
	while($r=fetch($q))
	{
		$menu[$r["parent"]][]=$r;
	}
	$ret="<select name='$name' id='selectmn' style='width:200px;'>";
	$ret.="<option value=0 data-level='0'>Root</option>\n";
	foreach($menu[0] as $mn)
	{
		$ret.="<option value=$mn[id] data-level='0' ".($mn["id"]==$selected?"selected=''":"").">$mn[name]</option>\n";
		if(count($menu[$mn["id"]])>0)
		foreach($menu[$mn["id"]] as $sub1_mn)
		{
			$ret.="<option value=$sub1_mn[id] data-level='1'".($sub1_mn["id"]==$selected?"selected=''":"").">$sub1_mn[name]</option>\n";
		}
	}
	$ret.="</select>";
	$ret.="<script>
			 function format(state) {
				var originalOption = state.element;
				var level=$(originalOption).data('level');
				if(level=='0')
					return \"<img class='flag' src='./img/folder.png' alt='' />\" + state.text;
				if(level=='1')
					return \"<img class='flag' src='./img/ico_page.png' alt='' / style='margin-left:30px;'>\" + state.text;
					
			}
			$(\"#selectmn\").select2({
				formatResult: format,
				formatSelection: format,
				escapeMarkup: function(m) { return m; }
			});
			</script>";
	return $ret;
}
?>